package com.ghost.model
{
	import com.ghost.UI.Ghost_Btn;
	import com.ghost.event.Pop_win_event;
	import com.ghost.manager.Effect_manager;
	import com.ghost.manager.Load_manager;
	import com.ghost.manager.Tip_manager;
	import com.ghost.utils.Debug;
	import com.ghost.view.login.Select_server;
	import com.ghost.vo.equipment.Equipment_list;
	import com.ghost.vo.game_configure.Game_configure_list;
	import com.ghost.vo.loading.Loading_list;
	import com.ghost.vo.role.Role_list;
	import com.ghost.vo.server_list.Server_list;
	import com.ghost.vo.static_tip.Static_tip_list;
	
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.setTimeout;

	/**
	 * 资源数据加载
	 * @author ghost
	 */
	public class Main_start
	{
		public var mc:Sprite;
		private var ld:Loader;
		public function Main_start()
		{
		}
		//加载初始资源
		public function load_source():void
		{
			Load_manager.get_Instance().add(Configure_url.xml_url+"static_tip.xml",Loading_data.type_xml,Global_data.loading_des_list["static_tip.xml"].des_str,static_tip_Handler);
			Load_manager.get_Instance().add(Configure_url.xml_url+"net.xml",Loading_data.type_xml,Global_data.loading_des_list["net.xml"].des_str,net_Handler);
			Load_manager.get_Instance().add(Configure_url.xml_url+"game_configure.xml",Loading_data.type_xml,Global_data.loading_des_list["game_configure.xml"].des_str,game_configure_Handler);
			Load_manager.get_Instance().add(Configure_url.xml_url+"server.xml"+"?"+String(int(Math.random()*10000)),Loading_data.type_xml,Global_data.loading_des_list["server.xml"].des_str,server_Handler);
			Load_manager.get_Instance().add(Configure_url.xml_url+"role.xml",Loading_data.type_xml,Global_data.loading_des_list["role.xml"].des_str,role_Handler);
			Load_manager.get_Instance().add(Configure_url.xml_url+"equipment.xml",Loading_data.type_xml,Global_data.loading_des_list["equipment.xml"].des_str,equipment_Handler);
			Load_manager.get_Instance().add(Configure_url.swf_url+"global_ui.swf",Loading_data.type_swf,Global_data.loading_des_list["global_ui.swf"].des_str,global_ui_Handler);
			Load_manager.get_Instance().add(Configure_url.swf_url+"Component_skin.swf",Loading_data.type_swf,Global_data.loading_des_list["Component_skin.swf"].des_str,Component_skin_Handler);
			Load_manager.get_Instance().start();
		}
		//加载net.xml完成
		private function net_Handler(data:*):void
		{
			Global_data.game_ip = XML(data).game_ip.toString();
			Global_data.game_port = Number(XML(data).game_port.toString());
		}
		//加载staitc_xml完成 
		private function static_tip_Handler(url_ld_data:*):void
		{
			var static_tip_xml:Static_tip_list = new Static_tip_list(XML(url_ld_data));
			Object_pool.data_obj_pool.put('static_tip_xml',static_tip_xml);
		}
		//游戏一些基础设置
		private function game_configure_Handler(data:*):void
		{
			var s:Game_configure_list = new Game_configure_list(XML(data));	
			Global_data.game_configure_list = s.list;
		}
		//服务器列表
		private function server_Handler(data:*):void
		{
			var ghost:Server_list = new Server_list(XML(data));
			Object_pool.data_obj_pool.put('server_xml',ghost);
		}
		//角色信息
		private function role_Handler(data:*):void
		{
			var ghost:Role_list = new Role_list(XML(data));
			Object_pool.data_obj_pool.put('role_xml',ghost);
		}
		//装备数据
		private function equipment_Handler(data:*):void
		{
			var ghost:Equipment_list = new Equipment_list(XML(data));
			Object_pool.data_obj_pool.put('equipment_xml',ghost);
		}
		private function Component_skin_Handler(ld:Loader):void
		{
			trace(ld.content,2222)
			Object_pool.ui_data_pool.put("Component_skin",ld);
			UI_skin_data.ghost_btn_skin_v = Object_pool.ui_data_pool.get("Component_skin").content.btn_skin_v[0];
			UI_skin_data.ghost_scroll_skin_v = Object_pool.ui_data_pool.get("Component_skin").content.scroll_skin_v[0];
			UI_skin_data.ghost_combobox_skin_v = Object_pool.ui_data_pool.get("Component_skin").content.combobox_skin_v[0];
			UI_skin_data.ghost_tip_skin_o = Object_pool.ui_data_pool.get("Component_skin").content.tip_skin_v;
			UI_skin_data.ghost_tip_skin_v = UI_skin_data.ghost_tip_skin_o[0];
			//trace(UI_skin_data.ghost_combobox_skin_v,UI_skin_data.ghost_tip_skin_v[0]);
			if(Global_data.game_configure_list['debug']=="1")
			{
				//启用debug模式
				Debug.allowLog = true;
			}
			Global_data.equipment_v = new <String>["equipment_xml"]
			Global_data.stage_max_width = Number(Global_data.game_configure_list['max_stage_width']);
			Global_data.stage_max_height = Number(Global_data.game_configure_list['max_stage_height']);
			mc.dispatchEvent(new Event('end'));
			//init();
		}
		private function global_ui_Handler(data:Loader):void
		{
			trace(data.content,11111)
			Global_data.grid_ui_h = Object(data.content).nine_grid_h;
			Global_data.obj_ui_h = Object(data.content).global_obj_h;
		}
		private function init():void
		{
			/*var arr:Array= new Array(1,2,3,4,5,6,7,8);
			var mc:MovieClip = new MovieClip();
			for(var i:int= 0;i<20;i++)
			{
			var btn22:Ghost_Btn = new Ghost_Btn(UI_skin_data.ghost_btn_skin_v);
			btn22.y = i*(btn22.height+5);
			btn22.setsize(67,27);
			btn22.label="fuck"+String(i);
			mc.addChild(btn22);
			}
			mc.scrollRect=new Rectangle(0,0,mc.width,100);
			this.addChild(mc);
			var mc_scroll:Ghost_mc_scroll = new Ghost_mc_scroll(UI_skin_data.ghost_scroll_skin_v);
			this.addChild(mc_scroll);
			mc_scroll.target = mc;
			mc_scroll.move_to(mc.x+mc.width,mc.y);
			mc_scroll.mouse_wheel = true;
			var combobox:Ghost_combobox = new Ghost_combobox(100,18);
			this.addChild(combobox);
			combobox.x = 200;
			combobox.prompt = "请选择..";
			combobox.set_data(arr,Ghost_Btn,true);
			var r:Rectangle = new Rectangle(0,0,100,150);
			combobox.setscrollrec = r;*/
			/*var txt:Ghost_TLF_txt = new Ghost_TLF_txt(100,150,Global_data.hash_map.get('scroll'));
			this.addChild(txt);
			txt.insert_object(mc,mc.width,mc.height,0,0);
			txt.selectable = false;*/
		}
	}
}